/*
 * Connection.h
 *
 *  Created on: 2009-02-12
 *      Author: ck
 */

#ifndef CONNECTION_H_
#define CONNECTION_H_
//#include <QObject>
#include <QTcpSocket>
#include <QStringList>

class ConnectionPlayer : public QTcpSocket {
Q_OBJECT;
public:
	ConnectionPlayer(QObject * parent = 0);
	virtual ~ConnectionPlayer();
	void sendMessage(QString cmd, QStringList args = QStringList());

public:
    QString getNick() const
    {
        return nick;
    }

    void setNick(QString nick)
    {
        this->nick = nick;
    }
    int getId() const
	{
		return id;
	}

	void setId(int id)
	{
		this->id = id;
	}

	bool getReady() {
		return this->isReady;
	}

	void setReady(bool s) {
		this->isReady=s;
	}
	bool getSitting() {
		return this->isSitting;
	}

	void setSitting(bool s) {
		this->isSitting=s;
	}
	void resetData();
    //void onDisconnected();
protected:
	//void newMessage(Connection* conn, qint8 param, qint8 args[], int argcnt);
	//void socketDisconnected(ConnectionPlayer*);
signals:
    void newMessage(ConnectionPlayer *conn, QString cmd, QStringList args);
    void socketDisconnected(ConnectionPlayer*);
public slots:
    void readMessage();
    //void onStateChange(QAbstractSocket::SocketState);
    void onDisconnected();


private:
	qint16 blockSize;
	QString nick;
	int id; //id == -1; nie jest jeszcze zaakceptowany, 0 = spectator; 1-4 - gracz
	bool isReady;
	bool isSitting;

};

#endif /* CONNECTION_H_ */
